<template>
  <div id="MyAgent">
    <div class="SQList">
      <ul>
        <li v-for="(item, index) in contentData1" :key="index" v-if="item.show" @click="contentDataClick1(item)">
          <p style="font-weight: bold; line-height: 60px">
            <img :src="item.img" alt="" style="display: block; float: left; width: 44px; height: 44px; margin: 6px" />
            <span style="float: left">{{ item.name }}</span>
            <span style="float: right; margin-left: 2px; color: red; font-size: 20px">{{ item.num }}</span>
          </p>
        </li>
      </ul>
    </div>
    <div class="bottom">
      <ul>
        <li
          :key="index"
          v-for="(item, index) in bottomData"
          @click="bottomClick(index)"
          v-show="($store.state.isGJ && (item.name === '首页' || item.name === '我的待办' || item.name === '我的收藏')) || (!$store.state.isGJ && (item.name === '首页' || item.name === '我的待办'))"
          :style="{
            color: nowIndex === index ? '#007AFF' : '#908f94',
            fontSize: '18px',
            width: $store.state.isGJ ? '33.3%' : '50%'
          }">
          <img v-if="nowIndex === index" :src="item.icon" />
          <img v-else :src="item.icons" />
          <p>{{ item.name }}</p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { QuerySignCallback, personToDoList, JFDataList, GetPrecredit, FileServerProxy, getDoorplateList } from '../../utils/api'
import { GJDBFunction } from '../../utils/queryData'
import { GJDBFunction2 } from '../../utils/queryData'
export default {
  name: 'MyAgent',
  data() {
    return {
      nowIndex: 1,
      contentData5: [],
      showTC: false,
      contentData1: [],
      contentData2: [
        {
          name: '建房待办',
          num: 0,
          show: true,
          img: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/55.png'
        },
        // {
        //   name: "我的贷款申请",
        //   num: 0,
        //   show: true,
        //   img: "https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/56.png",
        // },
        // {
        //   name: "我购买的保险",
        //   num: 0,
        //   show: true,
        //   img: "https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/57.png",
        // },
        // {
        //   name: "我要改扩建申请",
        //   num: 0,
        //   show: true,
        // },
        // {
        //   name: "危改待办",
        //   num: 0,
        //   show: true,
        //   img: "https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/58.png",
        // },
        // {
        //   name: "我的门牌办理申请",
        //   num: 0,
        //   show: true,
        //   img: "https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/59.png",
        // },
        // {
        //   name: "我要流转申请",
        //   num: 0,
        //   show: true,
        // },
        // {
        //   name: "我要办理不动产权证申请",
        //   num: 0,
        //   show: true,
        //   img: "https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/59.png"
        // },
      ],
      contentData3: [
        {
          name: '我要建房申请',
          num: 0,
          show: true,
          img: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/55.png'
        },
        // {
        //   name: '我的施工备案申请',
        //   num: 0,
        //   show: true,
        //   img: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/56.png'
        // },
        // {
        //   name: "我购买的保险",
        //   num: 0,
        //   show: true,
        //   img: "https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/57.png",
        // },
        // {
        //   name: "我要改扩建申请",
        //   num: 0,
        //   show: true,
        // },
        {
          name: '我要危改申请',
          num: 0,
          show: true,
          img: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/58.png'
        },
        {
          name: '我的门牌办理申请',
          num: 0,
          show: true,
          img: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/59.png'
        }
        // {
        //   name: "我要办理不动产权证申请",
        //   num: 0,
        //   show: true,
        //   img: "https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/60.png",
        // },
      ],
      bottomData: [
        {
          name: '首页',
          icon: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/20.png',
          icons: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/20-1.png'
        },
        {
          name: '我的待办',
          icons: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/21.png',
          icon: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/21-1.png'
        },
        {
          name: '我的收藏',
          icons: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/22.png',
          icon: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/22-1.png'
        }
      ]
    }
  },
  methods: {
    getcontentData: async function (data) {
      //获取危改申请个数
      this.contentData = []
      this.contentData1[0].num = 0
      this.contentData1[1].num = 0
      let paramswgCount = {
        householderIdcard: window.localStorage.getItem('DanDianid'),
        pageNo: 1,
        pageSize: 100000000
      }
      const reswgcount = await personToDoList(paramswgCount)
      if (reswgcount.data && reswgcount.data.data && reswgcount.data.data.pageList) {
        this.contentData1[1].num = reswgcount.data.data.totalCount
      }

      // this.contentData = []
      // this.contentData1[0].num = 0
      // // this.contentData1[1].num = 0;
      // let params = {
      //   accessCode: '',
      //   cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '',
      //   certNums: JSON.parse(window.localStorage.getItem('DanDianid'))
      //     ? JSON.parse(window.localStorage.getItem('DanDianid'))
      //     : '',
      // }
      // const req = await GetPrecredit(params)
      // this.contentData1[1].num = req.data.data.length
      // // 获取危改申请个数
      // let paramswg = {
      //   accessCode: '688bd3883572440a859dfd8ba9194e7b',
      //   cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
      //   params: {
      //     dataguid: '8a77ece9-212c-4599-8e18-014fdeb41524',
      //     searchObject: JSON.stringify([]),
      //     token: window.localStorage.getItem('token'),
      //   },
      // }
      // const reswg = await FileServerProxy(paramswg)
      // if (reswg.data.code == 200) {
      //   this.contentData1[1].num = JSON.parse(reswg.data.data).Data.length
      //   let params1 = {
      //     accessCode: '688bd3883572440a859dfd8ba9194e7b',
      //     cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
      //     params: {
      //       dataguid: '20966a43-764f-43ac-9c7c-ca0d440e5605',
      //       searchObject: JSON.stringify([]),
      //       token: window.localStorage.getItem('token'),
      //     },
      //   }
      //   const resq = await FileServerProxy(params1)
      //   this.contentData1[1].num += JSON.parse(resq.data.data).Data.length
      //}
      if (!this.$store.state.isGJ) {
        // let params = {
        //   dataguid: '9d97398e-6e18-45f1-932b-bd59cb54a0be',
        //   searchObject: [],
        //   token: window.localStorage.getItem('token'),
        // }
        // let params1 = {
        //   accessCode: '688bd3883572440a859dfd8ba9194e7b',

        //   cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
        //   params: params,
        // }
        // var res = await QuerySignCallback(params1)
        var res = await GJDBFunction('CRAFTSMAN', '1')
        // if (res.length == 0) {
        //   let params1 = {
        //     // "dataguid": "5a898987-5c64-4857-92c8-469d05c92c0c",
        //     dataguid: '9d97398e-6e18-45f1-932b-bd59cb54a0be',
        //     searchObject: [],
        //     bizGuid: 'd718f2a6-6d0a-42d2-9f03-e396fd056b79',
        //     token: window.localStorage.getItem('token'),
        //   }
        //   let params2 = {
        //     accessCode: '688bd3883572440a859dfd8ba9194e7b',

        //     cityCode: window.localStorage.getItem('citycode')
        //       ? window.localStorage.getItem('citycode')
        //       : '441300000000',
        //     params: params1,
        //   }
        //   var res1 = await QuerySignCallback(params2)
        //   var parmes = eval('(' + res1.data.data + ')').Data
        //   this.contentData1[0].num = parmes.length
        //   this.contentData = parmes
        // } else {
        //   this.contentData1[0].num = eval('(' + res.data.data + ')').Data.length
        //   var parmes = eval('(' + res.data.data + ')').Data
        //   this.contentData = parmes
        // }
        this.contentData1[0].num = res.length
        var parmes = res
        this.contentData = parmes
        this.contentData.length == 0 ? (this.noData = true) : (this.noData = false)
      }
      //农户逻辑
      else if (this.$store.state.isGJ) {
        // 获取施工备案待办列表
        const res23 = await GJDBFunction2('get_sgxkdb', [{ i_taskid: 1 }])
        const resNew = await GJDBFunction2('get_sgxkdbV2', [{ i_taskid: 1 }])
        // this.contentData3[1].num = res23.length
        // let params2 = {
        //   accessCode: '688bd3883572440a859dfd8ba9194e7b',

        //   cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
        //   params: {
        //     dataguid: '5a898987-5c64-4857-92c8-469d05c92c0c',
        //     searchObject: [],
        //     bizGuid: 'd718f2a6-6d0a-42d2-9f03-e396fd056b79',
        //     token: window.localStorage.getItem('token'),
        //   },
        // }
        // var parmes = {}
        // var res = await QuerySignCallback(params2)
        // parmes = eval('(' + res.data.data + ')').Data
        // let params3 = {
        //   accessCode: '688bd3883572440a859dfd8ba9194e7b',

        //   cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
        //   params: {
        //     dataguid: '8478109f-1194-4126-ab97-b2f927368e7b',
        //     searchObject: [],
        //     bizGuid: 'd718f2a6-6d0a-42d2-9f03-e396fd056b79',
        //     token: window.localStorage.getItem('token'),
        //   },
        // }
        // var res1 = await QuerySignCallback(params3)
        // let paer = eval('(' + res1.data.data + ')').Data
        // this.contentData = parmes

        // paer.forEach((item) => {
        //   this.contentData.push(item)
        // })
        // this.contentData1[0].num = this.contentData.length
        const res2 = await JFDataList(window.localStorage.getItem('DanDianid'))
        // this.contentData = res2.data.data.pageList
        this.contentData1[0].num = res2.data.data.totalCount
        let idcard = window.localStorage.getItem('DanDianid')

        let xcfycjtex = {
          procName: 'MPBL',
          dtParams: JSON.stringify([{ I_USERID: "'" + idcard + "'", TYPE: 5 }]),
          token: window.localStorage.getItem('token')
        }
        let xcfycjtfn = {
          accessCode: '69db6bece3a7480592e2ec753d1e335e',
          cityCode: window.localStorage.getItem('citycodeChange') ? window.localStorage.getItem('citycodeChange') : '441300000000',
          params: xcfycjtex
        }
        const resxcfycjt = await FileServerProxy(xcfycjtfn)
        let data = JSON.parse(resxcfycjt.data.data).Data
        this.contentData1[2].num = data.length
      }
      if (!this.$store.state.isGJ) {
        let params = {
          pageSize: '1000',
          pageNo: '1',
          cityCode: window.localStorage.getItem('citycodeChange') ? window.localStorage.getItem('citycodeChange') : '441300000000',
          appKey: '6738c6db-69e8-11ec-a673-6805cab640a0',
          accessCode: '40f38b1856c740529bdaed08f8d59e6d',
          proposerName: '',
          proposerOwnerIdentityNumber: ''
        }
        const res = await getDoorplateList(params)
        if (res.data.code == 200) {
          this.contentData1[4].num = res.data.data.pageList.length
        }
      }
      this.contentData.length == 0 ? (this.noData = true) : (this.noData = false)
    },
    getGJData: async function (data) {
      if (!this.$store.state.isGJ) {
        // let params = {
        //   dataguid: '9d97398e-6e18-45f1-932b-bd59cb54a0be',
        //   searchObject: [],
        //   token: window.localStorage.getItem('token'),
        // }
        // let params1 = {
        //   accessCode: '688bd3883572440a859dfd8ba9194e7b',
        //   cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
        //   params: params,
        // }
        // var res = await QuerySignCallback(params1)
        const res = await GJDBFunction('CRAFTSMAN', '1', window.localStorage.getItem('citycodeChange'))
        // if (eval('(' + res.data.data + ')').Data.length == 0) {
        //   let params1 = {
        //     // "dataguid": "5a898987-5c64-4857-92c8-469d05c92c0c",
        //     dataguid: '8478109f-1194-4126-ab97-b2f927368e7b',
        //     searchObject: [],
        //     bizGuid: 'd718f2a6-6d0a-42d2-9f03-e396fd056b79',
        //     token: window.localStorage.getItem('token'),
        //   }
        //   let params2 = {
        //     accessCode: '688bd3883572440a859dfd8ba9194e7b',

        //     cityCode: window.localStorage.getItem('citycode')
        //       ? window.localStorage.getItem('citycode')
        //       : '441300000000',
        //     params: params1,
        //   }
        //   var res1 = await QuerySignCallback(params2)
        //   var parmes = eval('(' + res1.data.data + ')').Data
        //   this.contentData2[0].num = parmes.length
        //   this.contentData = parmes
        // } else {
        this.contentData2[0].num = res.length
        var parmes = res
        this.contentData = parmes
        // }
      }
    },
    contentDataClick1(item) {
      switch (item.name) {
        case '建房待办':
          this.$router.push({
            path: 'BuildingApplication'
          })
          break
        case '我要建房申请':
          this.$router.push({
            path: 'BuildingApplication'
          })
          break
        case '我的施工备案申请':
          this.$router.push({
            path: '/mySGXKSQ'
          })
          break
        case '我要危改申请':
          this.$router.push({
            path: '/RebuildList',
            query: { data: '我要危改申请' }
          })
          break
        case '我的贷款申请':
          this.$router.push({
            path: 'LoanApplication'
          })
          break
        case '我的门牌办理申请':
          this.$router.push({
            path: 'BrandApplication'
          })
          break
      }
    },
    bottomClick(index) {
      switch (index) {
        case 0:
          this.$router.push({
            path: '/ZLJIndex'
          })
          break
        case 1:
          //获取数据长度
          // this.getcontentData();
          this.$router.push({
            path: 'MyAgent'
          })
          break
        case 2:
          this.$router.push({
            path: 'MyEnshrine'
          })
          break
      }
    }
  },
  mounted() {
    // if !this.$store.state.isGJ) {
    //   this.contentData1.forEach(item => {
    //     if (item.name === "我要改扩建申请" || item.name === "我要流转申请" || item.name === "我要办理不动产权证申请") {
    //       item.show = false
    //     }
    //   })
    // }
    // contentData1
    if (!this.$store.state.isGJ) {
      this.contentData1 = this.contentData2
    } else {
      this.contentData1 = this.contentData3
    }
    this.getcontentData()
    this.getGJData()
    if (ZWJSBridge) {
      ZWJSBridge.setTitle({
        title: '我的待办'
      })
        .then((res) => {})
        .catch((err) => {})
    }
  }
}
</script>

<style scoped lang="scss">
#MyAgent {
  height: 100vh;
  font-family: 'Helvetica Neue', Helvetica, STHeiTi, sans-serif;
  font-size: 14px;
  -webkit-overflow-scrolling: touch;
  touch-action: auto;
  .SQList {
    width: 100vw;
    height: calc(100vh - 50px);
    background: #fff;
    .title {
      width: 100%;
      height: 50px;
      background: #007aff;
      line-height: 50px;
      text-align: center;
      color: #ffffff;
      font-size: 20px;
      position: relative;
    }
    ul li {
      padding: 10px;
      height: 80px;
      // border: 1px solid #d2d2d2;
      border-radius: 14px;
      margin: 10px;
      margin-bottom: 10px;
    }
    ul li:first-child {
      background: #f1f6ff;
    }
    ul li:nth-child(2) {
      background: #fff0e4;
    }
    ul li:nth-child(3) {
      background: #dffff5;
    }
    ul li:nth-child(4) {
      background: #f6efff;
    }
    ul li:nth-child(5) {
      background: #fff0e4;
    }
    ul li:nth-child(6) {
      background: #f1f6ff;
    }
  }
  .bottom {
    clear: both;
    // position: fixed;
    bottom: 0;
    // height: 100px;
    width: 100%;
    text-align: center;
    background: #ffffff;
    border-top: 1px solid #d2d2d2;
    ul {
      width: 100%;
      height: 100%;
      clear: both;
      overflow: hidden;
      display: flex;
      height: 50px;
      align-items: center;
      li {
        float: left;
        width: 33.3%;
        font-size: 14px !important;
        img {
          height: 16px;
          margin-bottom: 3px;
        }
      }
    }
  }
}
</style>
